package patterns.design.e3t6;

import java.net.MalformedURLException;
import java.util.Scanner;

public class Client {
	
	private ResourcesProvider provider;
	private String userInput;
	private Scanner inputScanner;
	private Resource r;
	
	public Client() {
		inputScanner = new Scanner(System.in);
		provider = new Cache(new Downloader());
	}
	
	private void test() {
		do {
			System.out.println("Specify URL (type 'c' to end program):");
			userInput = inputScanner.nextLine();
			try
			{
				r = provider.provideResource(userInput);
				System.out.println("Resource from: " + userInput + " provided.");
			}
			catch (Exception e) 
			{
				if(!"c".equalsIgnoreCase(userInput))
				{
					System.err.println("There is no content to download.");
					e.printStackTrace();
				}
			}
		} while (!"c".equalsIgnoreCase(userInput));
	}

	public static void main(String[] args) {		
		Client client = new Client();
		client.test();
	}

}
